// @ts-ignore
import uuid from '../utils/UUIDUtils'
import RelayRequest from '../utils/RelayRequest'

const BASE_URL = 'https://bizser.njtrh.com:9954/getaway/openApi'

export default function(bizContent: Object, method: string){
    return new Promise((resolve, reject) => {
        uni.request({
            url: BASE_URL,
            method: 'POST',
            header: {
                'Content-Type': 'text/plain; charset=utf-8'
            },
            data: RelayRequest({
                bizContent,
                method,
                bizId: uuid()
            }),
            success: res => {
                let data = res.data as any
                if(data.rspCode !== '200') {
                    reject(data.rspMsg)
                } else if(data.bizRspCode === '9004'){
                    reject('登录超时, 重新登录')
                    getApp().globalData.toLogin()
                } else if(data.bizRspCode !== '1'){
                    reject(data.bizRpsMsg)
                } else {
                    if(data.bizContent) {
                        resolve(JSON.parse(data.bizContent))
                    } else {
                        resolve('')
                    }
                }
            },
            fail: err => {
                reject(err)
            }
        })
    })
}
